package com.leo.javase.thread.test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 使用NIO分割一个20G的文件，分割为若干小文件
 * @author Administrator
 */
public class ReadBigFileWithNIO {
	public static void main(String args[]) throws IOException {
		/*FileInputStream fin = new FileInputStream("C:\\TDDOWNLOAD\\query.log.td");
		FileChannel fcin = fin.getChannel();
		ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024 * 50);
		while (true) {
			buffer.clear();
			int flag = fcin.read(buffer);
			if (flag == -1) {
				break;
			}
			buffer.flip();
			FileOutputStream fout = new FileOutputStream("d:\\temp\\"+ Math.random() + ".log");
			FileChannel fcout = fout.getChannel();
			fcout.write(buffer);
			System.out.println(buffer);
		}*/
		
		System.out.println(Runtime.getRuntime().availableProcessors());
		
	}
}
